﻿package mvc_model
{
	import flash.events.Event;
	
	public class Users extends Model
	{
		private var _usersList:XMLList;
		
		private var _currentUser:XML;
		private var _currentTitle:String;
		private var _currentImage:String;
		
		public function UsersModel() {}
		
		public function get usersList():XMLList
		{
			return _usersList;
		}
		
		public function get username():String
		{
			return _currentUser.username;
		}
		
		public function get firstName():String
		{
			return _currentUser.firstName;
		}
		
		public function get lastName():String
		{
			return _currentUser.lastName;
		}
		
		public function get email():String
		{
			return _currentUser.email;
		}
		
		public function get dob():String
		{
			return _currentUser.dob;
		}		
		
		public function get city():String
		{
			return _currentUser.city;
		}
		
		public function get country():String
		{
			return _currentUser.country;
		}
		
		public function get gender():String
		{
			return _currentUser.gender;
		}
		
		public function get availability():String
		{
			return _currentUser.availability;
		}
		
		public function get avatar():String
		{
			return _currentUser.avatar;
		}
		
		public function get currentImage():String
		{
			return _currentImage;
		}
		
		public function get currentTitle():String
		{
			return _currentTitle;
		}
		
		override protected function updateData():void
		{
			// set the current user to be the user at index 'currentIndex'
			_currentUser = _usersList[currentIndex];
			
			// set the total number of users in the list
			totalItems = _usersList.length();
			
			_currentTitle = _currentUser.firstName + " " + _currentUser.lastName;
			_currentImage = _currentUser.avatar;
		}
		
		override protected function dataLoaded(event:Event):void
		{
			data = new XML(loader.data);
			
			// set the list of all users
			_usersList = data.user;
			setCurrentIndex(currentIndex);
		}
	}
}